package top.mable.utils;

import org.apache.commons.lang.Validate;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class ReflectUtil {

    public static List<Field> getAllFieldsList(final Class cls) {
        Validate.isTrue(cls != null, "The class must not be null");
        final List allFields = new ArrayList();
        Class currentClass = cls;
        while (currentClass != null) {
            final Field[] declaredFields = currentClass.getDeclaredFields();
            for (final Field field : declaredFields) {
                allFields.add(field);
            }
            currentClass = currentClass.getSuperclass();
        }
        return allFields;
    }
}
